package com.atguigu.system.handler;

import com.atguigu.common.result.Result;
import com.atguigu.system.exception.GuiguException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class GloballExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result resoveException(Exception e){
        return  Result.fail();
    }
    //创建一个处理数学异常的方法
    @ExceptionHandler(ArithmeticException.class)
    public Result resoveArithmeticException(ArithmeticException e){
        e.printStackTrace();
        return Result.fail().message(e.getMessage());
    }
    //处理自定义异常的方法
    @ExceptionHandler(GuiguException.class)
    public Result resoveGuiguException(GuiguException e){
        e.printStackTrace();
        return  Result.fail().message(e.getMessage()).code(e.getCode());
    }
}
